package com.lzh.dlykserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzh.dlykserver.constant.Constants;
import com.lzh.dlykserver.entity.TDicValue;
import com.lzh.dlykserver.mapper.TDicValueMapper;
import com.lzh.dlykserver.query.DicValueDTO;
import com.lzh.dlykserver.service.DicValueService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class DicValueServiceImpl implements DicValueService {

    private final TDicValueMapper tDicValueMapper;

    @Override
    public PageInfo<TDicValue> getDicValues(Integer current, DicValueDTO dicValueDTO) {
        //设置PageHelper
        PageHelper.startPage(current, Constants.PAGE_SIZE);
        //查询
        List<TDicValue> list = tDicValueMapper.getDicValues(dicValueDTO);
        //封装分页数据到PageInfo
        PageInfo<TDicValue> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public TDicValue getDicValueById(Integer id) {
        return tDicValueMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteDicValueById(Integer id) {
        return tDicValueMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteDicValueByIds(List<String> idList) {
        return tDicValueMapper.deleteDicValueByIds(idList);
    }

    @Override
    public int editDicValue(TDicValue dicValue) {
        return tDicValueMapper.updateByPrimaryKeySelective(dicValue);
    }

    @Override
    public int addDicValue(TDicValue dicValue) {
        return tDicValueMapper.insertSelective(dicValue);
    }
}
